<?xml version="1.0" encoding="iso-8859-1"?>

<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Class: ActiveBackground::Manager</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />

    <script language="JavaScript" type="text/javascript">
    // <![CDATA[

        function toggleSource( id )
        {
          var elem
          var link

          if( document.getElementById )
          {
            elem = document.getElementById( id )
            link = document.getElementById( "l_" + id )
          }
          else if ( document.all )
          {
            elem = eval( "document.all." + id )
            link = eval( "document.all.l_" + id )
          }
          else
            return false;

          if( elem.style.display == "block" )
          {
            elem.style.display = "none"
            link.innerHTML = "show source"
          }
          else
          {
            elem.style.display = "block"
            link.innerHTML = "hide source"
          }
        }

        function openCode( url )
        {
          window.open( url, "SOURCE_CODE", "width=400,height=400,scrollbars=yes" )
        }
      // ]]>
    </script>

  </head>

  <body>
  <table width="100%" border='0' cellpadding='0' cellspacing='0' class='banner'><tr>
  <td class="file-title"><span class="file-title-prefix">Class</span><br />ActiveBackground::Manager</td>
  <td align="right">
    <table cellspacing=0 cellpadding=2>
      <tr valign="top">
        <td>In:</td>
        <td>

<a href="../../files/vendor/plugins/active_background/tasks/__/lib/active_background/manager_rb.html">vendor/plugins/active_background/tasks/../lib/active_background/manager.rb</a>
        </td>
      </tr>
    <tr>
      <td>Parent:</td>
      <td>
        <a href="Base.html">
Base
         </a>

     </td>
   </tr>
         </table>
        </td>
        </tr>
      </table>
 <!-- banner header -->

  <div id="bodyContent">
      <div id="content">




  <div class="sectiontitle">Methods</div>
  <ul>
  <li><a href="#M000087">add_job</a></li>
  <li><a href="#M000078">alive?</a></li>
  <li><a href="#M000071">config=</a></li>
  <li><a href="#M000085">each_job</a></li>
  <li><a href="#M000086">get_job</a></li>
  <li><a href="#M000084">get_jobs</a></li>
  <li><a href="#M000070">init</a></li>
  <li><a href="#M000083">job_count</a></li>
  <li><a href="#M000075">merge!</a></li>
  <li><a href="#M000079">name</a></li>
  <li><a href="#M000080">name=</a></li>
  <li><a href="#M000073">process</a></li>
  <li><a href="#M000088">remove_job</a></li>
  <li><a href="#M000072">run</a></li>
  <li><a href="#M000081">send_command_to_job</a></li>
  <li><a href="#M000074">stop</a></li>
  <li><a href="#M000076">terminate</a></li>
  <li><a href="#M000077">terminated?</a></li>
  <li><a href="#M000082">wait</a></li>
  </ul>


<div class="sectiontitle">Included Modules</div>
<ul>
  <li>Singleton</li>
</ul>






<div class="sectiontitle">Public Instance methods</div>
<div class="method">
  <div class="title">
    <a name="M000087"></a><b>add_job</b>(key, job)
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000087_source')" id="l_M000087_source">show source</a> ]</p>

  <div id="M000087_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/manager.rb, line 172</span>
172:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add_job</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">job</span>)
173:       <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">info</span>(<span class="ruby-value str">&quot;Manager: adding job to queue&quot;</span>)
174:       <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span>
175:         <span class="ruby-identifier">merge!</span>
176:         <span class="ruby-keyword kw">begin</span>
177:           <span class="ruby-ivar">@lock</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
178:             <span class="ruby-ivar">@queue</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">job</span>
179:             <span class="ruby-ivar">@threads</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-keyword kw">nil</span>
180:             <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-node">&quot;Manager: Adding job to queue #{@queue.size} with #{@jobs.size} already running&quot;</span>)
181:           <span class="ruby-keyword kw">end</span>
182:         <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
183:           <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">error</span>(<span class="ruby-value str">&quot;\n******************************************\n&quot;</span> <span class="ruby-operator">+</span>
184:                         <span class="ruby-node">&quot;Exception: #{e.to_s} - (#{e.class})\n&quot;</span> <span class="ruby-operator">+</span>
185:                         <span class="ruby-value str">&quot;Manager: Faile while adding job\n&quot;</span> <span class="ruby-operator">+</span>
186:                         <span class="ruby-value str">&quot;----------------BACKTRACE-----------------\n&quot;</span> <span class="ruby-operator">+</span>
187:                                   <span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;\n&quot;</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;\n&quot;</span> <span class="ruby-operator">+</span>
188:                         <span class="ruby-value str">&quot;-------------------END--------------------\n&quot;</span> <span class="ruby-operator">+</span>
189:                         <span class="ruby-value str">&quot;\n******************************************\n&quot;</span> )
190:         <span class="ruby-keyword kw">end</span>
191:       <span class="ruby-keyword kw">end</span>
192:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000078"></a><b>alive?</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000078_source')" id="l_M000078_source">show source</a> ]</p>

  <div id="M000078_source" class="dyn-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/manager.rb, line 93</span>
93:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">alive?</span>
94:       <span class="ruby-keyword kw">true</span>
95:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000071"></a><b>config=</b>(config)
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000071_source')" id="l_M000071_source">show source</a> ]</p>

  <div id="M000071_source" class="dyn-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/manager.rb, line 16</span>
16:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">config=</span>(<span class="ruby-identifier">config</span>)
17:       <span class="ruby-ivar">@@config</span>=<span class="ruby-identifier">config</span>
18:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000085"></a><b>each_job</b>() {|key, job| ...}
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000085_source')" id="l_M000085_source">show source</a> ]</p>

  <div id="M000085_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/manager.rb, line 150</span>
150:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">each_job</span>
151:       <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">info</span>(<span class="ruby-value str">&quot;Manager: passing jobs one by one&quot;</span>)
152:       <span class="ruby-identifier">merge!</span>
153:       <span class="ruby-ivar">@lock</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
154:         <span class="ruby-ivar">@jobs</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">job</span><span class="ruby-operator">|</span>
155:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
156:             <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">key</span>, <span class="ruby-identifier">job</span>
157:           <span class="ruby-keyword kw">else</span>
158:             <span class="ruby-comment cmt"># TODO: raise error</span>
159:           <span class="ruby-keyword kw">end</span>
160:         <span class="ruby-keyword kw">end</span>
161:       <span class="ruby-keyword kw">end</span>
162:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000086"></a><b>get_job</b>(key)
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000086_source')" id="l_M000086_source">show source</a> ]</p>

  <div id="M000086_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/manager.rb, line 164</span>
164:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_job</span>(<span class="ruby-identifier">key</span>)
165:       <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">info</span>(<span class="ruby-value str">&quot;Manager: Get specific job&quot;</span>)
166:       <span class="ruby-identifier">merge!</span>
167:       <span class="ruby-ivar">@lock</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
168:         <span class="ruby-ivar">@jobs</span>[<span class="ruby-identifier">key</span>]
169:       <span class="ruby-keyword kw">end</span>
170:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000084"></a><b>get_jobs</b>() {|@jobs| ...}
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000084_source')" id="l_M000084_source">show source</a> ]</p>

  <div id="M000084_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/manager.rb, line 138</span>
138:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_jobs</span>
139:       <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">info</span>(<span class="ruby-value str">&quot;Manager: getting ALL jobs&quot;</span>)
140:       <span class="ruby-identifier">merge!</span>
141:       <span class="ruby-ivar">@lock</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
142:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
143:           <span class="ruby-keyword kw">yield</span> <span class="ruby-ivar">@jobs</span>
144:         <span class="ruby-keyword kw">else</span>
145:           <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@jobs</span>
146:         <span class="ruby-keyword kw">end</span>
147:       <span class="ruby-keyword kw">end</span>
148:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000070"></a><b>init</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000070_source')" id="l_M000070_source">show source</a> ]</p>

  <div id="M000070_source" class="dyn-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/manager.rb, line 5</span>
 5:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">init</span>
 6:       <span class="ruby-ivar">@jobs</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>
 7:       <span class="ruby-ivar">@queue</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>
 8:       <span class="ruby-ivar">@running</span> = <span class="ruby-keyword kw">true</span>
 9:       <span class="ruby-ivar">@lock</span> = <span class="ruby-constant">Monitor</span>.<span class="ruby-identifier">new</span>
10:       <span class="ruby-ivar">@threads</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>
11:       <span class="ruby-ivar">@terminated</span> = <span class="ruby-keyword kw">nil</span>
12:       <span class="ruby-ivar">@logger</span> = <span class="ruby-constant">ACTIVE_BACKGROUND_CONFIG</span>.<span class="ruby-identifier">logger</span>
13:       <span class="ruby-identifier">run</span>
14:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000083"></a><b>job_count</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000083_source')" id="l_M000083_source">show source</a> ]</p>

  <div id="M000083_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/manager.rb, line 132</span>
132:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">job_count</span>
133:       <span class="ruby-ivar">@lock</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
134:         <span class="ruby-ivar">@jobs</span>.<span class="ruby-identifier">size</span>
135:       <span class="ruby-keyword kw">end</span>
136:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000075"></a><b>merge!</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000075_source')" id="l_M000075_source">show source</a> ]</p>

  <div id="M000075_source" class="dyn-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/manager.rb, line 70</span>
70:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">merge!</span>
71:       <span class="ruby-ivar">@lock</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
72:         <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">info</span>(<span class="ruby-node">&quot;Manager: Merging jobs (#{@jobs.size}) with queue (#{@queue.size}) resulting in #{@jobs.size + @queue.size} running jobs&quot;</span>)
73:         <span class="ruby-ivar">@jobs</span>.<span class="ruby-identifier">merge!</span>(<span class="ruby-ivar">@queue</span>)
74:         <span class="ruby-ivar">@queue</span>=<span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>
75:       <span class="ruby-keyword kw">end</span>
76:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000079"></a><b>name</b>(name=nil)
  </div>
<div class="aka">
  This method is also aliased as
  <a href="Manager.html#M000080">name=</a>
</div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000079_source')" id="l_M000079_source">show source</a> ]</p>

  <div id="M000079_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/manager.rb, line 97</span>
 97:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">name</span>(<span class="ruby-identifier">name</span>=<span class="ruby-keyword kw">nil</span>)
 98:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">name</span>
 99:         <span class="ruby-ivar">@name</span>=<span class="ruby-identifier">name</span>
100:       <span class="ruby-keyword kw">else</span>
101:         <span class="ruby-ivar">@name</span>
102:       <span class="ruby-keyword kw">end</span>
103:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000080"></a><b>name=</b>(name=nil)
  </div>
  <div class="description">

  <p>
Alias for <a href="Manager.html#M000079">name</a>
</p>
  </div>
</div>
<div class="method">
  <div class="title">
    <a name="M000073"></a><b>process</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000073_source')" id="l_M000073_source">show source</a> ]</p>

  <div id="M000073_source" class="dyn-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/manager.rb, line 40</span>
40:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">process</span>
41:       <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@jobs</span>.<span class="ruby-identifier">empty?</span>
42:         <span class="ruby-comment cmt"># Need to figure out how to prevent hash modified during iteration</span>
43:         <span class="ruby-ivar">@lock</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
44:           <span class="ruby-ivar">@jobs</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">job</span><span class="ruby-operator">|</span>
45:             <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@terminated</span>
46:               <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-node">&quot;Manager: Processing job(#{key}) #{job.inspect}&quot;</span>)
47:               <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">job</span>.<span class="ruby-identifier">status</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:created</span>
48:                 <span class="ruby-ivar">@threads</span>[<span class="ruby-identifier">job</span>.<span class="ruby-identifier">key</span>] = <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span>
49:                   <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-value str">'Manager: process job with key '</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>
50:                   <span class="ruby-identifier">job</span>.<span class="ruby-identifier">process</span>()
51:                 <span class="ruby-keyword kw">end</span>
52:               <span class="ruby-keyword kw">else</span>
53:                 <span class="ruby-identifier">remove_job</span>(<span class="ruby-identifier">job</span>.<span class="ruby-identifier">key</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">job</span>.<span class="ruby-identifier">terminated?</span>
54:               <span class="ruby-keyword kw">end</span>
55:             <span class="ruby-keyword kw">end</span>
56:             <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">&quot;Manager: #{@jobs.length} jobs in queue&quot;</span>
57:           <span class="ruby-keyword kw">end</span>
58:         <span class="ruby-keyword kw">end</span>
59:       <span class="ruby-keyword kw">end</span>
60:       <span class="ruby-identifier">merge!</span>
61:       <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-node">&quot;Manager: Waiting #{@@config.server(name).sleep} seconds with #{@jobs.size} jobs running&quot;</span>)
62:       <span class="ruby-constant">GC</span>.<span class="ruby-identifier">start</span>
63:       <span class="ruby-identifier">sleep</span> <span class="ruby-ivar">@@config</span>.<span class="ruby-identifier">server</span>(<span class="ruby-identifier">name</span>).<span class="ruby-identifier">sleep</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@terminated</span>
64:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000072"></a><b>run</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000072_source')" id="l_M000072_source">show source</a> ]</p>

  <div id="M000072_source" class="dyn-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/manager.rb, line 20</span>
20:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>
21:       <span class="ruby-keyword kw">begin</span>
22:         <span class="ruby-ivar">@thread</span> = <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span>
23:           <span class="ruby-keyword kw">while</span> <span class="ruby-ivar">@running</span>
24:             <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">&quot;Manager: busy... with #{@jobs.length} jobs&quot;</span>
25:             <span class="ruby-identifier">process</span>
26:           <span class="ruby-keyword kw">end</span>
27:         <span class="ruby-keyword kw">end</span>
28:       <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
29:         <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">error</span>(<span class="ruby-value str">&quot;\n******************************************\n&quot;</span> <span class="ruby-operator">+</span>
30:                       <span class="ruby-node">&quot;Exception: #{e.to_s} - (#{e.class})\n&quot;</span> <span class="ruby-operator">+</span>
31:                       <span class="ruby-value str">&quot;Manager: Failed while running server\n&quot;</span> <span class="ruby-operator">+</span>
32:                       <span class="ruby-value str">&quot;----------------BACKTRACE-----------------\n&quot;</span> <span class="ruby-operator">+</span>
33:                                 <span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;\n&quot;</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;\n&quot;</span> <span class="ruby-operator">+</span>
34:                       <span class="ruby-value str">&quot;-------------------END--------------------\n&quot;</span> <span class="ruby-operator">+</span>
35:                       <span class="ruby-value str">&quot;\n******************************************\n&quot;</span> )
36:         <span class="ruby-identifier">run</span>
37:       <span class="ruby-keyword kw">end</span>
38:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000081"></a><b>send_command_to_job</b>(key, method, *args)
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000081_source')" id="l_M000081_source">show source</a> ]</p>

  <div id="M000081_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/manager.rb, line 106</span>
106:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">send_command_to_job</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">method</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
107:       <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">info</span>(<span class="ruby-node">&quot;Manager: Sending command to job (#{key})&quot;</span>)
108:       <span class="ruby-identifier">merge!</span>
109:       <span class="ruby-keyword kw">begin</span>
110:         <span class="ruby-ivar">@lock</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
111:           <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">empty?</span>
112:             <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@jobs</span>[<span class="ruby-identifier">key</span>].<span class="ruby-identifier">send</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">args</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@jobs</span>[<span class="ruby-identifier">key</span>]
113:           <span class="ruby-keyword kw">else</span>
114:             <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@jobs</span>[<span class="ruby-identifier">key</span>].<span class="ruby-identifier">send</span>(<span class="ruby-identifier">method</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@jobs</span>[<span class="ruby-identifier">key</span>]
115:           <span class="ruby-keyword kw">end</span>
116:         <span class="ruby-keyword kw">end</span>
117:       <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
118:         <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">error</span>(<span class="ruby-value str">&quot;\n******************************************\n&quot;</span> <span class="ruby-operator">+</span>
119:                       <span class="ruby-node">&quot;Exception: #{e.to_s} - (#{e.class})\n&quot;</span> <span class="ruby-operator">+</span>
120:                       <span class="ruby-value str">&quot;Manager: Cannot send command to job\n&quot;</span> <span class="ruby-operator">+</span>
121:                       <span class="ruby-value str">&quot;----------------BACKTRACE-----------------\n&quot;</span> <span class="ruby-operator">+</span>
122:                                 <span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;\n&quot;</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;\n&quot;</span> <span class="ruby-operator">+</span>
123:                       <span class="ruby-value str">&quot;-------------------END--------------------\n&quot;</span> <span class="ruby-operator">+</span>
124:                       <span class="ruby-value str">&quot;\n******************************************\n&quot;</span> )
125:       <span class="ruby-keyword kw">end</span>
126:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000074"></a><b>stop</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000074_source')" id="l_M000074_source">show source</a> ]</p>

  <div id="M000074_source" class="dyn-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/manager.rb, line 66</span>
66:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stop</span>
67:       <span class="ruby-ivar">@running</span> = <span class="ruby-keyword kw">false</span>
68:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000076"></a><b>terminate</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000076_source')" id="l_M000076_source">show source</a> ]</p>

  <div id="M000076_source" class="dyn-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/manager.rb, line 78</span>
78:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">terminate</span>
79:       <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@terminated</span> <span class="ruby-keyword kw">and</span> <span class="ruby-operator">!</span><span class="ruby-ivar">@running</span>
80:         <span class="ruby-ivar">@lock</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
81:           <span class="ruby-ivar">@terminated</span> = <span class="ruby-keyword kw">true</span>
82:           <span class="ruby-ivar">@running</span> = <span class="ruby-keyword kw">false</span>
83:         <span class="ruby-keyword kw">end</span>
84:       <span class="ruby-keyword kw">end</span>
85:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000077"></a><b>terminated?</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000077_source')" id="l_M000077_source">show source</a> ]</p>

  <div id="M000077_source" class="dyn-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/manager.rb, line 87</span>
87:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">terminated?</span>
88:       <span class="ruby-ivar">@lock</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
89:         <span class="ruby-ivar">@terminated</span>
90:       <span class="ruby-keyword kw">end</span>
91:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000082"></a><b>wait</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000082_source')" id="l_M000082_source">show source</a> ]</p>

  <div id="M000082_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/manager.rb, line 128</span>
128:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">wait</span>
129:       <span class="ruby-ivar">@thread</span>.<span class="ruby-identifier">join</span>
130:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>

<div class="sectiontitle">Private Instance methods</div>
<div class="method">
  <div class="title">
    <a name="M000088"></a><b>remove_job</b>(key)
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000088_source')" id="l_M000088_source">show source</a> ]</p>

  <div id="M000088_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/manager.rb, line 195</span>
195:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">remove_job</span>(<span class="ruby-identifier">key</span>)
196:         <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">info</span>(<span class="ruby-value str">&quot;Manager: removing job&quot;</span>)
197:         <span class="ruby-identifier">merge!</span>
198:         <span class="ruby-ivar">@lock</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
199:           <span class="ruby-ivar">@jobs</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">key</span>)
200:           <span class="ruby-ivar">@threads</span>[<span class="ruby-identifier">key</span>].<span class="ruby-identifier">kill</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@threads</span>[<span class="ruby-identifier">key</span>]
201:           <span class="ruby-ivar">@threads</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">key</span>)
202:         <span class="ruby-keyword kw">end</span>
203:       <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
</div>

  </div>

    </body>
</html>